package com.zhyl.demo.controller;

import com.zhyl.demo.entity.Patient;
import com.zhyl.demo.entity.User;
import com.zhyl.demo.service.PatientService;
import com.zhyl.demo.service.impl.PatientServiceImpl;
import com.zhyl.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author yang3
 */
@RestController
@RequestMapping("/patient")
public class PatientController {

    private final PatientService patientService;
    @Autowired
    private PatientController(PatientService patientService){
        this.patientService = patientService;
    }

    @RequestMapping("/showInfo")
    public Result showInfo(Integer patid){
        Patient patient = patientService.showInfo(patid);
        if (patient!=null){
            return Result.success(patient);
        }else {
            return Result.error("-1","访问错误");
        }

    }

    @RequestMapping("/getAllPatient")
    public Result getAllPatient(){
        ArrayList<Patient> allPatient = patientService.getAllPatient();
        return Result.success(allPatient);
    }

    @RequestMapping("/updateInfo")
    public Result updateInfo(@RequestBody Patient patient)
    {
        if (patient==null){
            return Result.error("信息填写有误","-1");
        }
        Boolean res = patientService.updateInfo(patient);
        if (res){
            return Result.success();
        }else {
            return Result.error("-1","修改失败");
        }
    }

    @RequestMapping("/addBalance")
    public Result addBalance(@RequestBody Patient patient){
        if (patient==null){
            return Result.error("参数错误","-1");
        }
        Boolean res = patientService.addBalance(patient);

        if (res) {
            return Result.success(patient);
        }else {
            return Result.error("-1","充值失败");
        }
    }

}
